import { JSEncrypt } from 'jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
  'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='

const privateKey =
  'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
  '7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
  'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
  'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
  'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
  'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
  'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
  'UP8iWi1Qw0Y='

// 加密
export const encrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export const decrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}

const loginPublicKey = `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA49N6LnVcdISu++ZmYaWV
lRPrAUwrbxhJy816Z4I8DeaqAJG7t2jXywBbWOn9/0jDcI+a55hcqEU+cNbkb31W
Pr8CdYrMX2p93gWE+gz2gsrEZFrLtqavzSQ2Yb3C4qO22iuQdtNAeBFjrq6AqVFV
67InX3LByRqm7RDGx+6x9XBilWTMadS3oQgnvuQTcPjZohbGSDydw1KL2ERk7Y0U
3fL2UTHHvAGNV5mk8fRjeWzeT7a2Ck1UsT9ZctLtAi7YAobhP+0ISCwW4Tnb1Td9
NCrO2sNEx0lXwo8HUOr9k0dTJbuDT5cldjocXkbIWyATjpWbcPcj8trxXseADrLq
nQIDAQAB`

// 加密传输用户账户密码信息
export const encryptLogin = (txt: string) => {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(loginPublicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}
